home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / n2ctclib10.lha / n2c / Source / TCL_n2c.c < prev    next >
C/C++ Source or Header  |  1997-01-30  |  5KB  |  249 lines

  1.  
  2. #include <exec/types.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7.  
  8. #include <proto/intuition.h>
  9. #include <proto/dos.h>
  10. #include <proto/exec.h>
  11.  
  12. #define _USEOLDEXEC_ 
  13.  
  14. struct DosLibrary        *DOSBase         = NULL;
  15.  
  16.  
  17. struct MainData
  18. {
  19.     LONG DosBase,           
  20.  
  21.      GfxBase,            
  22.      IntuitionBase,      
  23.      LayersBase,         
  24.      DiskFontBase,       
  25.      WBBase,             
  26.      ASLBase,
  27.      IFFParseBase,
  28.      RexxBase,
  29.      AmigaGuideBase,
  30.      LocaleBase,
  31.      FirstWindow ,       
  32.      FirstSheet,         
  33.      FirstFont,          
  34.      FontList,           
  35.      LocaleCatalog,      
  36.      AmigaGuideHandle,   
  37.      Screen,             
  38.      Com_DiskErrorAdr;   
  39. };
  40.  
  41.  
  42. #define Decine \
  43. switch(cur)\
  44. {\
  45.     case '1':    switch(next)\
  46.                 {\
  47.                     case '0': strcat(to,"dieci"); break;\
  48.                     case '1': strcat(to,"undici"); break;\
  49.                     case '2': strcat(to,"dodici"); break;\
  50.                     case '3': strcat(to,"tredici"); break;\
  51.                     case '4': strcat(to,"quattordici"); break;\
  52.                     case '5': strcat(to,"quindici"); break;\
  53.                     case '6': strcat(to,"sedici"); break;\
  54.                     case '7': strcat(to,"diciassette"); break;\
  55.                     case '8': strcat(to,"diciotto"); break;\
  56.                     case '9': strcat(to,"diciannove"); break;\
  57.                 }\
  58.     break;\
  59.     case '2':   if ((next=='1')||(next=='8')) strcat(to,"vent");\
  60.                 else strcat(to,"venti");\
  61.     break;\
  62.     case '3':   if ((next=='1')||(next=='8')) strcat(to,"trent");\
  63.                 else strcat(to,"trenta");\
  64.     break;\
  65.     case '4':   if ((next=='1')||(next=='8')) strcat(to,"quarant");\
  66.                 else strcat(to,"quaranta");\
  67.     break;\
  68.     case '5':   if ((next=='1')||(next=='8')) strcat(to,"cinquant");\
  69.                 else strcat(to,"cinquanta");\
  70.     break;\
  71.     case '6':   if ((next=='1')||(next=='8')) strcat(to,"sessant");\
  72.                 else strcat(to,"sessanta");\
  73.     break;\
  74.     case '7':   if ((next=='1')||(next=='8')) strcat(to,"settant"); \
  75.                 else strcat(to,"settanta"); \
  76.     break;\
  77.     case '8':   if ((next=='1')||(next=='8')) strcat(to,"ottant");\
  78.                 else strcat(to,"ottanta"); \
  79.     break;\
  80.     case '9':   if ((next=='1')||(next=='8')) strcat(to,"novant");\
  81.                 else  strcat(to,"novanta");\
  82.     break;\
  83. }
  84.  
  85. #define Unita \
  86. switch(cur)                                        \
  87. {                                                  \
  88.     case '1':    strcat(to,"un"     ); break; \
  89.     case '2':    strcat(to,"due"     );    break; \
  90.     case '3':    strcat(to,"tre"    );    break; \
  91.     case '4':    strcat(to,"quattro"); break; \
  92.     case '5':    strcat(to,"cinque" );    break; \
  93.     case '6':    strcat(to,"sei"    );    break; \
  94.     case '7':    strcat(to,"sette"  );    break; \
  95.     case '8':    strcat(to,"otto"   );    break; \
  96.     case '9':    strcat(to,"nove"   );    break; \
  97. } \
  98.  
  99.  
  100. // Converts a 3 digit string to a character string
  101.  
  102. void __inline ncc(char from[] , char to[])
  103. {
  104.     char cur,next;
  105.  
  106.     cur  = from[0];
  107.  
  108.     if (cur != '1' && cur != '0')
  109.     {  
  110.         Unita
  111.  
  112.         strcat(to,"cento"); 
  113.     }
  114.     else if (cur=='1')
  115.         strcat(to,"cento"); 
  116.  
  117.     cur  = from[1];
  118.     next = from[2];
  119.  
  120.     Decine; 
  121.  
  122.     if(cur != '1')
  123.     {
  124.         cur  = from[2];
  125.         Unita; 
  126.     }
  127. }
  128.  
  129. void __inline n2c(char from[] , char to[], LONG opt)
  130. {
  131.     int len,p,parti,resto;
  132.  
  133.     char tmp[13];                        
  134.  
  135.     char g[4];
  136.  
  137.     tmp[0] = '0';
  138.     tmp[1] = '0';
  139.     tmp[2] = '\0';
  140.  
  141.  
  142.     len   = strlen(from);
  143.     resto = len % 3;
  144.  
  145.  
  146.     if(resto != 0)
  147.     {
  148.         LONG rsp = 3 - resto;
  149.  
  150.         strcpy(tmp+rsp,from);             // Sovrascrive partendo da 1 o da 2, ovvero da (3 - resto) (Max: 2)
  151.  
  152.         len += rsp;                        
  153.     }
  154.     else
  155.         strcpy(tmp,from);                 // Sovrascrive partendo da 0
  156.  
  157.  
  158.     parti = len / 3;                    
  159.  
  160.  
  161.     #define fg (3 * p)                
  162.  
  163.  
  164.     #define cond0 ((g[2] == '1') && (g[1] != '1'))
  165.     #define cond1 (((g[2]!= '1') && (g[2] != '0'))|| (g[1] != '0') || (g[0] != '0'))
  166.     #define cond2 ((g[2] == '1') && (g[1] == '0') && (g[0] == '0'))
  167.  
  168.  
  169.  
  170.     for(p = 0; p < parti; p++)
  171.     {
  172.         g[0] = tmp[fg  ];
  173.         g[1] = tmp[fg+1];
  174.         g[2] = tmp[fg+2];
  175.         g[3] = '\0';
  176.  
  177.         switch(parti-p)
  178.         {
  179.             case 1:                        
  180.  
  181.                 if(opt == 0)            // IF options > 1 -> if(opt > 0)
  182.                 {
  183.                     ncc(g,to);
  184.  
  185.                     if(cond0)
  186.                         strcat(to,"o");
  187.                 }
  188.                 else
  189.                     strcat(to,g);
  190.  
  191.                 break;
  192.  
  193.             case 2:                        
  194.                 if(cond1)
  195.                 {
  196.                     ncc(g,to);
  197.                     strcat(to,"mila");
  198.                 }
  199.                 else if(cond2) strcat(to,"mille");
  200.  
  201.                 break;
  202.  
  203.             case 3:                        
  204.                 if(cond1)
  205.                 {
  206.                     ncc(g,to);
  207.                     strcat(to,"milioni");
  208.                 }
  209.                 else if(cond2) strcat(to,"unmilione");
  210.  
  211.                 break;
  212.  
  213.             case 4:                        
  214.                 if(cond1)
  215.                 {
  216.                     ncc(g,to);
  217.                     strcat(to,"miliardi");
  218.                 }
  219.                 else if(cond2) strcat(to,"unmiliardo");
  220.                 break;
  221.         }
  222.     }
  223. }
  224.  
  225.  
  226.  
  227. // a2: char *        (destination buffer)
  228. // d2: LONG            (source number       )
  229. // d3: LONG            (options           )
  230. // a5: MainData *     
  231.  
  232.  
  233. // Options:            (mutual exclusive)
  234. //
  235. // 0 = normal form    i.e. millecinquecento
  236. // 1 = short form    i.e. mille500
  237.  
  238. extern __asm __saveds void CTCL_n2c(register __a2 char to[], register __d2 LONG from, register __d3 LONG opt, register __a5 struct MainData *md)
  239. {
  240.     char num[13];
  241.  
  242.     DOSBase = (struct DosLibrary *) md->DosBase;
  243.  
  244.     stcl_d(num,from);                    // From LONG to char    (from -> num)
  245.  
  246.     n2c(num,to,opt);                    // From numeric string to char string (num -> to)
  247. }
  248.  
  249.